Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(frontend): intempestive re-render of form #1019

Merged
merged 3 commits into from
Jul 10, 2019
Merged

Conversation

UnbearableBear
Copy link
Contributor

@UnbearableBear UnbearableBear commented Jul 10, 2019

I created a related issue here for the remainings: #1021

@UnbearableBear UnbearableBear requested a review from lionelB July 10, 2019 09:51
onSubmit={onSubmit}
onUpdate={setValues}
rules={rules}
stepReducer={stepReducer}
Copy link
Contributor Author

@UnbearableBear UnbearableBear Jul 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the main idea of the fix is to delegate the handling of the steps to the wizard. So now, the steps are managed inside of it and not above it, and therefore fix the rerendering issue when changing them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we can still configure it as before by providing initialStepIndex, InitialValues, initialSteps and rules.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can not group Rules and stepReducer since they are really inter-dependant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea ! But I need to figure out how

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no problem, we can do it later :) we can add a reminder

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to create an issue

dispatch({ type: "add_branche", payload: steps });
} else {
dispatch({ type: "remove_branche" });
const Rules = ({ values, dispatch }) => (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to make sure we have access to values and dispatch which are in the wizard below, I had to transform rules into a component

rules = null
initialValues = {},
Rules = null,
stepReducer
}) {
const [stepIndex, setStepIndex] = useState(initialStepIndex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we merge this state part into the reducer ?

Copy link
Contributor Author

@UnbearableBear UnbearableBear Jul 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so because the stepIndex is something internal to the wizard. So asking to the consumer of wizard to code it in the reducer would mean it could also impact the way pagination is handled. But it should not except for the initial step index. The only thing index can configure is the steps displayed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in fact I would leave the stepReducer up to the user but include it in a "WizzardReducer" wich handle the setIndex something like

case steps: return {...state, steps: stepReducer(state.steps, action)}

since reducers can be combined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I added this to the issue aswell, I will get back at it as soon as the planning gets more lightweight.

return action.payload;

case "reset": {
return initialSteps;

This comment was marked as resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep !

Copy link
Contributor

@lionelB lionelB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just few question but nice refacto 👍

@UnbearableBear UnbearableBear mentioned this pull request Jul 10, 2019
10 tasks
@UnbearableBear
Copy link
Contributor Author

Bump !

initialStepIndex: PropTypes.number,
onSubmit: PropTypes.func.isRequired
initialValues: PropTypes.object,
Rules: PropTypes.func
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PropTypes.node should it works for func and element)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to dislike it. Maybe it is because it is a basic function component ?
Screenshot 2019-07-10 at 15 48 45

@UnbearableBear UnbearableBear requested a review from lionelB July 10, 2019 14:07
@UnbearableBear UnbearableBear merged commit 35e4da5 into master Jul 10, 2019
@lionelB lionelB deleted the manu/fix-rerender branch July 10, 2019 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants